#pragma once

#ifndef CONTACT_H
#define CONTACT_H

#include "Particle.h"

/**
 * A contact represents two objects in contact (in this case
 * particle contact representing two particles). Resolving a contact 
 * removes their interpenetration, and applies sufficient impulse
 * to keep them apart. Colliding bodies may also rebound.
 *
 * The contact has no callable functions, it just holds the contact
 * details. To resolve a set of contacts, use the particle contact
 * resolver class.
 */
class Contact
{
public:
	/**
	 * Holds the particles that are involved in the contact. The
	 * second of these can be NULL for contacts with the scenery.
	 */
	Particle* particle[2];
	/**
	 * Holds the amount each particle is moved by during 
	 * interpenetration resolution.
	 */
	D3DXVECTOR3	particleMovement[2];
	/** Holds the normal restitution coefficient at the contact. */
	float restitution;
	/** Holds the depth of penetration at the contact. */
	float penetration;
	/** Holds the direction of the contact in world coordinates. */
	D3DXVECTOR3 contactNormal;
	Contact(Particle* particle[2], float restitution, D3DXVECTOR3 contactNormal)
		: restitution(restitution), contactNormal(contactNormal)
	{
		this->particle[0] = particle[0];
		this->particle[1] = particle[1];
	}
	Contact(Particle* particle[2], float restitution, float penetration, D3DXVECTOR3 contactNormal)
		: restitution(restitution), penetration(penetration), contactNormal(contactNormal)
	{
		this->particle[0] = particle[0];
		this->particle[1] = particle[1];
	}
	~Contact() { }
	/** Resolves this contact for both velocity and interpenetration. */
	void resolve(float frameTime);
	/** Calculates the separating velocity at this contact. */
	float calculateSeparatingVelocity() const;
private:
	/** Handles the impulse calculations for this collision. */
	void resolveVelocity(float frameTime);
	/** Handles the iterpenetration resolution for this contact. */
	void resolveInterpenetration(float frameTime);
};

#endif